<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="发送验证码" id="btn">
    <script>
        var s=20;
        var timer;
        var btn=document.getElementById("btn");
        function show(){
            if(s<0){
                clearInterval(timer);
                btn.disabled=false;//启用按钮
                btn.value="发送验证码";
                s=20;
            }else{
                btn.disabled=true;//禁用按钮
                btn.value=`${s}秒后重发`;//0
                s--;
            }
           
        }
        btn.onclick=function(){
            timer=setInterval(show,200);
        };

    </script>
</body>
</html>